package com.orangelife.mobile.complaints.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.curry.android.adapter.FatherAdapter;
import com.curry.android.util.TimeUtil;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.util.DateUtil;

import java.util.List;
import java.util.Map;

/**
 * 投诉的服务反馈adapter
 * Created by heyucan on 2016/5/16.
 */
public class ComplainFeedbackAdapater<T> extends FatherAdapter<T> {

    private Context mContext;
    private LayoutInflater listContainer;
    private List<Map<String, Object>> item_name = null;

    public final class ListItemView {
        public TextView tv_feedback_time;
        public TextView tv_feedback_content;
    }

    public ComplainFeedbackAdapater(Context context,
                                    List<Map<String, Object>> item_name) {
        this.mContext = context;
        listContainer = LayoutInflater.from(mContext);
        this.item_name = item_name;
    }

    @Override
    public int getCount() {
        return item_name.size();
    }

    @Override
    public Object getItem(int position) {
        return item_name.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ListItemView listItemView;

        if (convertView == null) {
            listItemView = new ListItemView();
            convertView = listContainer.inflate(
                    R.layout.item_lv_complain_feedback, null);
            listItemView.tv_feedback_time = (TextView) convertView
                    .findViewById(R.id.tv_feedback_time);
            listItemView.tv_feedback_content = (TextView) convertView.findViewById(R.id.tv_feedback_content);
            convertView.setTag(listItemView);
        } else {
            listItemView = (ListItemView) convertView.getTag();
        }
        String time=String.valueOf(item_name.get(position).get("tsCreate"));
        listItemView.tv_feedback_time.setText(DateUtil.getInstance().tranStringForDate(time));
        listItemView.tv_feedback_content.setText(String.valueOf(item_name.get(position).get("feedbackContent")));
        return convertView;
    }


    @Override
    public BaseAdapter setList(List<T> list) {
        this.item_name = (List<Map<String, Object>>) list;
        return ComplainFeedbackAdapater.this;
    }
}


